Week 06: Computer Aided Design

Welcome! In this guide, we'll discuss how to program various functions in our component. After reviewing this week's assignment and consulting with some classmates, I made the decision to create a basic code for the PCB (Printed Circuit Board) to play the Happy Birthday song. Let's dive into the steps to achieve this

Grupal Assigment

Embedded Programming Overview

Architectures:
  • AVR (8-bit)
  • ARM Cortex-M0+
  • RISC-V (32-bit)
  • Xtensa (LX6/LX7)
  • Tensilica L106 (32-bit)
  • ARM Cortex-M4F
MCUs (Microcontrollers):

ATTiny45/85

Comparison:

Evaluating MCUs based on functionalities, dimensions, and performance.

Arithmetic Operations:

Comparison of arithmetic operations between 8-bit and 32-bit microcontrollers.

Cheat Sheet:
  • Syntax rules, control structures, functions, comments, basic GPIO usage, analog readings, timers, printing, PWM, and interrupts in Python and C++.
Examples:
  • Basic GPIO usage in Python, Arduino (C++), and MicroPython.
  • Analog readings in Python, Arduino (C++), and MicroPython.
  • Timers with blocking and non-blocking delays in Python, Arduino (C++), and MicroPython.
  • PWM usage in Python, Arduino (C++), and MicroPython.
  • Interrupt handling in Python and Arduino (C++).
  • Examples for using neopixels with Arduino, MicroPython, and CircuitPython.

Additionally, there are references to UF files for MicroPython and CircuitPython.


PROGRAMMING THE BOARD

For this practice I installed ARDUINO , MU EDITOR and THONNY


Arduino

Just to prove a difrent languaje I looked for an Arduino code that played the same song, just to compare the function and the sound of both languages. Then I found this cite ARDUINO SONGS "


Thonny

After doing a practice with Mu and Arduino i desided that Thonny provided a more simple interface, making it easy for me as a beginner to start coding in Python. Helping me reduce distractions, and allowing me detect easily where to star, how to stop and focus on writing and testing your code.

Overall, if you're new to programming or prefer a straightforward and Python-centric development environment, Thonny can be an excellent choice for writing and testing Python code.

  • Install and use First llok for the sofware at the tools and open the main and copy the basic code or start codeing. For the PCB to mach the xiao i needed to install RP2 or the predestinated library
  • Read the program: First we need to conect the board pressing the B bottom and it should look like the first pick then after getting the library download in the Xiao rp 2040 we need to set the port with the software just like I show in the pictures .
  • Play the program: In this part I conect the PCB and it sould not open the library, just select the port as I stated before and press play if you deside to sabe the code I sugest to save it in the computer beacuse each time I connected the board it used to reset the files within the RPI RP2.

  • FIRST CODE
    1. Understand the notes: First, you need to understand the frequencies associated with each note in the song you want to play. You can find tables or resources online that list the frequencies for each note.
    2. Map notes to frequencies: Once you have the frequencies for each note, you'll need to map them to corresponding frequencies in your code. You can use arrays, dictionaries, or switch statements to do this mapping.
    3. Define timing: Decide on the timing for each note. This includes the duration each note should play for and any rests between notes.
    4. Write the code: Using a programming language suitable for your hardware (such as C for Arduino or Python for Raspberry Pi), write code that iterates through the notes of the song, plays each note's corresponding frequency for the specified duration, and includes any necessary rests.
    5. Testing and adjustments: Test your code on your hardware to ensure it plays the song correctly. You may need to adjust the timing or frequencies to get the desired result.
    PLAY SONG

    Here's a simple example in Python for playing the "Happy Birthday" song using the frecuencies from Piano key frequencies - Wikipedia

    Timing of Playing the Song:

    The timing of playing the "Happy Birthday" song on the Xiao RP2040 will involve determining the duration of each note and any rests between notes. This timing can be achieved by specifying the duration of each note in milliseconds or microseconds, depending on the capabilities of the board and the programming language used.

    For example, a simple timing for playing the "Happy Birthday" song might involve playing each note for a fixed duration (e.g., 0.00001 milliseconds) and adding short rests (e.g., 100 milliseconds) between notes to create the rhythm of the song. However, the timing can be adjusted based on personal preference or to better match the original melody of the song.

    FINAL RESULT

    The final result would be a code written in a suitable programming language (such as C/C++ for the Arduino platform, CircuitPython or in this case MicroPython for the RP2040) that runs on the Xiao RP2040 microcontroller board. The code will play the "Happy Birthday" song by generating specific frequencies for each note and controlling the timing of each note's duration.

    Overall, the purpose was fulfilled by a code that accurately plays the "Happy Birthday" song on the Xiao RP2040, with precise timing for each note to create a recognizable rendition of the melody.